package com.kupurui.asteacher.ui.mine.setting;

import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.text.TextUtils;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.EditText;
import android.widget.TextView;

import com.android.frame.util.AppJsonUtil;
import com.kupurui.asteacher.R;
import com.kupurui.asteacher.http.Teacher;
import com.kupurui.asteacher.ui.BaseAty;
import com.kupurui.asteacher.utils.UserManger;

import butterknife.Bind;
import butterknife.ButterKnife;
import okhttp3.Call;
import okhttp3.Response;

/**
 * 意见反馈
 * Created by Administrator on 2017/7/17.
 */

public class FeedBackAty extends BaseAty {

    @Bind(R.id.tv_bar_title)
    TextView tvBarTitle;
    @Bind(R.id.m_toolbar)
    Toolbar mToolbar;
    @Bind(R.id.edit_feedback)
    EditText editFeedback;
    @Bind(R.id.edit_contact_information)
    EditText editContactInformation;

    private String content = "";
    private String contact = "";

    @Override
    public int getLayoutId() {
        return R.layout.feed_back_aty;
    }

    @Override
    public void initData() {
        initToolbar(mToolbar,"意见反馈");
    }

    @Override
    public void requestData() {

    }

    @Override
    public void onSuccess(String result, Call call, Response response, int what) {
        switch (what){
            case 0:
                showToast(AppJsonUtil.getResultInfo(result).getMessage());
                finish();
                break;
        }
        super.onSuccess(result, call, response, what);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu_submit, menu);
        return super.onCreateOptionsMenu(menu);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        if (item.getItemId() == R.id.menu_submit) {
            //提交意见
            send();
        }
        return super.onOptionsItemSelected(item);
    }

    private void send(){
        content = editFeedback.getText().toString();
        contact = editContactInformation.getText().toString();
        if (TextUtils.isEmpty(content)){
            showToast("请输入您的意见或建议");
            return;
        }
        if (TextUtils.isEmpty(contact)){
            showToast("请留下您的联系方式，方便我们与您联系");
            return;
        }
        showLoadingDialog("");
        new Teacher().suggest(UserManger.getId(),content,contact,this,0);
    }

}
